package amqp.tutorials.all;


import amqp.tutorials.all.direct.DirectSender;
import amqp.tutorials.all.fanout.FanoutSender;
import amqp.tutorials.all.header.HeadSender;
import amqp.tutorials.all.simple.MQSender;
import amqp.tutorials.all.topic.TopicSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RabbitMQController {

    @Autowired(required = false)
    private FanoutSender fanoutSender;


    @Autowired
    private MQSender mqSender;

    //方法：调用消息生产者，发送消息
    @GetMapping("/mq")
    public void mq() {
        mqSender.send("hello llp");
    }

    @GetMapping("/fanout")
    public void fanout() {
        fanoutSender.sendFanout("hello fanout");
    }

    @Autowired(required = false)
    private DirectSender directSender;


    @GetMapping("/direct")
    public void direct() {
        directSender.send("hello direct");
    }


    @Autowired(required = false)
    private TopicSender topicSender;

    @GetMapping("/topic")
    public void topic() {
        topicSender.send();
    }

    @Autowired
    private HeadSender headSender;

    @GetMapping("/head/{n}")
    public void head(@PathVariable int n) {

        if (n == 1) {
            headSender.sendHeader1("one");
        } else {
            headSender.sendHeader2("two");
        }

    }

}
